﻿using DevExpress.XtraEditors.Controls;
using RecruitStudents.Client.BLL;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Const;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RecruitStudents.Client.Financial
{
    public partial class Financial_OnSitePayFeeForm_Query_List : BaseForm
    {
        ServiceFinancial service = new ServiceFinancial();
        ServiceBase baseService = new ServiceBase();
        public Financial_OnSitePayFeeForm_Query_List()
        {
            InitializeComponent();
            InitData();
        }
        private void InitData()
        {
            #region 绑定考点列表
            DataTable dtExamCity = baseService.GetSysExamPlaceDataTable(string.Empty, string.Empty, "1");
            DataRow dr = dtExamCity.NewRow();
            dr["ExamPlaceNO"] = "";
            dr["ExamPlaceName"] = "";
            dtExamCity.Rows.InsertAt(dr, 0);
            txtExamCity.Properties.DataSource = dtExamCity;
            txtExamCity.Properties.Columns.Clear();
            txtExamCity.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("ExamPlaceNO", 30, "考点代码"));
            txtExamCity.Properties.Columns.Add(new LookUpColumnInfo("ExamPlaceName", 55, "考点名称"));
            txtExamCity.Properties.ValueMember = "ExamPlaceNO";
            txtExamCity.Properties.DisplayMember = "ExamPlaceName";
            txtExamCity.Properties.NullText = "";

            #endregion

            #region 绑定专业
            DataTable dtSpecialityKinds = baseService.GetSpecialityKindsTable(string.Empty, string.Empty, "1", string.Empty);
            DataRow drpecialityKinds = dtSpecialityKinds.NewRow();
            drpecialityKinds["SpecialityKindsNO"] = "";
            drpecialityKinds["SpecialityKindsName"] = "";
            dtSpecialityKinds.Rows.InsertAt(drpecialityKinds, 0);
            comboSpecialityKindsNO.Properties.DataSource = dtSpecialityKinds;
            comboSpecialityKindsNO.Properties.Columns.Clear();
            comboSpecialityKindsNO.Properties.Columns.Add(new LookUpColumnInfo("SpecialityKindsNO", 30, "专业代码"));
            comboSpecialityKindsNO.Properties.Columns.Add(new LookUpColumnInfo("SpecialityKindsName", 55, "专业名称"));
            comboSpecialityKindsNO.Properties.ValueMember = "SpecialityKindsNO";
            comboSpecialityKindsNO.Properties.DisplayMember = "SpecialityKindsName";
            comboSpecialityKindsNO.Properties.NullText = "";
            #endregion

            #region  绑定级别 
            comboExamLevel.Properties.DataSource = ConstExamLevel.DicExamLevel.ToList();
            comboExamLevel.Properties.Columns.Clear();
            comboExamLevel.Properties.Columns.Add(new LookUpColumnInfo("Key", 30, "级别编码"));
            comboExamLevel.Properties.Columns.Add(new LookUpColumnInfo("Value", 55, "级别名称"));
            comboExamLevel.Properties.ValueMember = "Key";
            comboExamLevel.Properties.DisplayMember = "Value";
            comboExamLevel.Properties.NullText = "";
            #endregion

            #region 绑定缴费来源
            this.comboPaySource.Properties.NullText = "";
            this.comboPaySource.Properties.Columns.Add(new LookUpColumnInfo("Value", 55, "缴费来源"));
            this.comboPaySource.Properties.DataSource = ConstPaySource.DicPaySource.ToList();
            this.comboPaySource.Properties.DisplayMember = "Value";
            this.comboPaySource.Properties.ValueMember = "Key";
            #endregion

            #region 绑定是否缴费
            this.cmbIsFee.Properties.NullText = "";
            this.cmbIsFee.Properties.Columns.Add(new LookUpColumnInfo("Value", 55, "是否缴费"));
            this.cmbIsFee.Properties.DataSource = ConstAppConfig.DicIsFee.ToList();
            this.cmbIsFee.Properties.DisplayMember = "Value";
            this.cmbIsFee.Properties.ValueMember = "Key";
            this.cmbIsFee.EditValue = "1";
            #endregion

        }
        #region 绑定gridControl1
        private void BindInfo()
        {
            string strExamPlaceID;
            string strExamLevel;
            string strSpecialityKindsNO;
            string strPaySource;
            string strIsFee;
            string strStartdate;
            string strEnddate;
            string strOrdNO;
            Dictionary<string, string> serchList = new Dictionary<string, string>();
            if (txtExamCity.Text != "")
                strExamPlaceID = txtExamCity.EditValue.ToString().Trim();
            else
                strExamPlaceID = txtExamCity.SelectedText;

            if (comboExamLevel.Text != "")
                strExamLevel = comboExamLevel.EditValue.ToString().Trim();
            else
                strExamLevel = comboExamLevel.SelectedText;

            if (comboSpecialityKindsNO.Text != "")
                strSpecialityKindsNO = comboSpecialityKindsNO.EditValue.ToString().Trim();
            else
                strSpecialityKindsNO = comboSpecialityKindsNO.SelectedText;

            if (comboPaySource.Text != "")
                strPaySource = comboPaySource.EditValue.ToString().Trim();
            else
                strPaySource = comboPaySource.SelectedText;

            if (cmbIsFee.Text != "")
                strIsFee = cmbIsFee.EditValue.ToString().Trim();
            else
                strIsFee = cmbIsFee.SelectedText;

            if (cmbStartdate.Text != "")
                strStartdate = cmbStartdate.EditValue.ToString().Trim();
            else
                strStartdate = cmbStartdate.SelectedText;

            if (cmbEnddate.Text != "")
                strEnddate = cmbEnddate.EditValue.ToString().Trim();
            else
                strEnddate = cmbEnddate.SelectedText;

            strOrdNO = comboOrdNO.Text;

            DataTable dt = service.SearchPayFeeInfo(strExamPlaceID, strExamLevel, strSpecialityKindsNO, strPaySource, strIsFee, strStartdate, strEnddate, strOrdNO);
            decimal sumMonery = 0;
            decimal money = 0;
            if (dt != null)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    if (dr["IsFee"].ToString() == "1")
                    {
                        dr["IsFee"] = "已缴费";
                    }
                    else
                    {
                        dr["IsFee"] = "未缴费";
                    }
                    if (!string.IsNullOrEmpty(dr["Fee"].ToString()) && !string.IsNullOrEmpty(dr["CounterFee"].ToString()))
                    {
                        money = Convert.ToDecimal(dr["Fee"].ToString()) + Convert.ToDecimal(dr["CounterFee"].ToString());
                        sumMonery += money;
                    }
                }
                gridControl1.DataSource = dt;
                double decMoney = Convert.ToDouble(sumMonery);
                lblAmont.Text = decMoney + "元";
            }
            else
            {
                gridControl1.DataSource = dt;
                lblAmont.Text = "0 元";
            }
        }
        #endregion

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            BindInfo();
        }
    }
}
